using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;


public class SelectUI : MonoBehaviour
{

    public SelectID selectHead;
    int headID;
    public SelectID selectBody;
    int bodyID;
    public RoleSelect roleSelect;
    public InputField inputName;
    public Button btnStart;
    void Start()
    {
        selectHead.onSelect(setHead);
        selectBody.onSelect(setBody);
        btnStart.onClick.AddListener(onEnterGame);
        inputName.text = PlayerPrefs.GetString("playerName");
        headID = PlayerPrefs.GetInt("headID");
        bodyID = PlayerPrefs.GetInt("bodyID");
        selectHead.ID = headID;
        selectBody.ID = bodyID;
        // setHead(headID);
        // setBody(bodyID);
        roleSelect.init();
    }

    void setHead(int id)
    {
        Debug.Log("头部ID:" + id);
        roleSelect.setHead(id);
        PlayerPrefs.SetInt("headID", id);
    }
    void setBody(int id)
    {
        Debug.Log("身体ID:" + id);
        roleSelect.setBody(id);
        PlayerPrefs.SetInt("bodyID", id);
    }

    void onEnterGame()
    {
        PlayerPrefs.SetString("playerName", inputName.text);
        SceneManager.LoadScene("Game");
    }
}
